#include<bits/stdc++.h>
using namespace std;
int a[200005],v[200005],n;
string tb(int x){
    stack<char>stk;
    while(x){
        stk.push(x%2+'0');
        x/=2;
    }
    string t;
    while(!stk.empty()){
        t+=stk.top();
        stk.pop();
    }
    while(t.length()<n){
        t="0"+t;
    }
    return t;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--){    
        scanf("%d",&n);
        for(int i=0;i<n;i++)scanf("%d",&a[i]);
        int maxn=-1;
        for(int i=0;i<pow(2,n);i++){
            memset(v,0,sizeof v);
            string bi=tb(i);
            for(int j=0;j<bi.length();j++){
                for(int k=i-1;k>=0;k--){
                    if(bi[k]==bi[i]){
                        if(a[i]==a[k])v[i]=a[i];
                        else break;
                    }
                }
            }
            int sum=0;
            for(int j=0;j<n;j++){
                sum+=v[j];
            }
            maxn=max(maxn,sum);
        }
        printf("%d\n",maxn);
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}